import Taro from "@tarojs/taro";
import {appName, qqMapKey} from "../service/evn";

export default {
    namespace: "app",
    state: {
        tabKey: 0,
        chartData: [],
        currentLocationInStore: {},
        chooseLocationInStore: {},
        isShow: false,
        isAuth: false,
        activeKey: "ask",
        searchValue: "",
        videoData: "",
        selected: 0,
    },
    subscriptions: {},
    effects: {
        * init() {
        },
        * jump({payload}) {
            const {key = ""} = payload;
            Taro.redirectTo({
                url: `/pages/${key}/index`,
            });
        },
        * showMap() {
            //使用在腾讯位置服务申请的key（必填）qqMapKey
            //调用插件的app的名称（必填）appName
            // eslint-disable-next-line no-undef
          Taro.navigateTo({
                url: "plugin://chooseLocation/index?key=" + qqMapKey + "&referer=" + appName,
            });
        },
        * chooseLocation() {
            Taro.chooseLocation({
                success: function (res) {
                    Taro.setStorageSync("chooseLocation", JSON.stringify(res));
                    Taro.reLaunch({url: '/pages/index/index'});
                },
            });
        },
    },
    reducers: {
        upState(state, {payload}) {
            return {
                ...state,
                ...payload,
            };
        },
    },
};
